﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace MotionPlanning.MotionPlanningComponents.MotionPlanningSystems.CollisionPrimitives
{
    abstract public class Polygon
    {
        protected List<double[]> Vertices;
        protected double[] Coordinates;

        public Polygon() { }

        public Polygon(string rawFile)
        {
            string[] separators = new string[] { "<vetex>", "</vetex>" };
            string[] entries = rawFile.Split(separators, StringSplitOptions.None);
            Vertices = new List<double[]>();
            int n_vertices = (entries.Length - 1) / 2;
            for (int i = 0; i < n_vertices; ++i)
                Vertices.Add(MotionPlanningUtils.StringToDoubleArray(entries[1 + i * 2]));

            separators = new string[] { "<position>", "</position>" };
            entries = rawFile.Split(separators, StringSplitOptions.None);
            this.Coordinates = MotionPlanningUtils.StringToDoubleArray(entries[1]);
        }

        abstract public bool IsCollidedWith(Polygon targetPolygon);

        abstract public bool IsCollidedWithIfAt(double[] coord, Polygon targetPolygon);

        abstract public void TransformToEnvironment(double[] coord, ref List<double[]> vertices_real);

        public List<double[]> Get_Vertices()
        {
            return Vertices;
        }
        public void Set_Vertices(List<double[]> vertices)
        {
            Vertices = vertices;
        }
        public double[] Get_Coordinates()
        {
            return Coordinates;
        }
        public void Set_Coordinates(double[] coordinates)
        {
            Coordinates = coordinates;
        }

    }
}
